package cn.bugstack.ai_autoclassification_qwen.service.batch;

import cn.bugstack.ai_autoclassification_qwen.service.TProductClassificationService;
import java.util.concurrent.BlockingQueue;

public class ProductWorker implements Runnable {

    private final BlockingQueue<ProductTask> queue;
    private final TProductClassificationService classificationService;

    public ProductWorker(BlockingQueue<ProductTask> queue,
                         TProductClassificationService classificationService) {
        this.queue = queue;
        this.classificationService = classificationService;
    }

    @Override
    public void run() {
        while (true) {
            try {
                ProductTask task = queue.take();
                classificationService.classifyProduct(task.id());
                Thread.sleep(200);  // 模型限流
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                break;
            } catch (Exception ex) {
                System.err.println("处理失败: " + ex.getMessage());
            }
        }
    }
}
